﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;

namespace nyxwin.Common.Base.Common
{
    public class NotifyingObject : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }

        protected void RaisePropertyChanged<T>(Expression<Func<T>> expression)
        {
            MemberExpression me = expression.Body as MemberExpression;

            if (me == null)
                throw new ArgumentException("Argument is not a member expression", "expression");

            var property = me.Member as PropertyInfo;
            if (property == null)
                throw new ArgumentException("Argument is not a property", "expression");

            var getMethod = property.GetGetMethod(true);
            if (getMethod.IsStatic)
                throw new ArgumentException("Argument cannot be a static property", "expression");

            var name = me.Member.Name;
            RaisePropertyChanged(name);
        }
        #endregion
    }
}
